package com.my.attendance.controller;

import com.my.attendance.entity.Department;
import com.my.attendance.service.BuMenService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/BuMenAdd")
public class BuMenAdd extends HttpServlet {
    private BuMenService buMenService=new BuMenService();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            req.setCharacterEncoding("utf-8");
            resp.setCharacterEncoding("utf-8");
            resp.setContentType("text/html;charset=utf-8");
            String department_number = req.getParameter("department_number");
            String name = req.getParameter("name");
            String manager = req.getParameter("manager");
            String telephone = req.getParameter("telephone");
            String address = req.getParameter("address");
            String notes = req.getParameter("notes");
            Department department = new Department();
            department.setDepartment_number(Integer.parseInt(department_number));
            department.setName(name);
            department.setManager(manager);
            department.setTelephone(telephone);
            department.setAddress(address);
            department.setNotes(notes);
            BuMenService buMenService = new BuMenService();
            buMenService.add(department);
            req.getRequestDispatcher("BuMenList").forward(req,resp);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
